from datetime import datetime
from .base import Base
from sqlalchemy.types import Integer
from sqlalchemy.schema import Column
from sqlalchemy.databases import mysql

__all__ = ["LogRecord"]

class LogRecord(Base):

    __tablename__ = "log"

    id = Column(Integer, primary_key=True)
    date = Column(mysql.DATETIME, nullable=False)
    level = Column(mysql.VARCHAR(10), nullable=False)
    name = Column(mysql.VARCHAR(32), nullable=False)
    remoteIp = Column(mysql.VARCHAR(32))
    message = Column(mysql.TEXT)

    def __init__(self, level, name, message, remoteIp=None):
        self.level = level
        self.name = name
        self.message = message
        self.remoteIp = remoteIp
        self.date = datetime.utcnow()